   $(document).ready(function(){
	  initSelectItem();
	  //第一次初始化展示所有的历史记录
	  
	  $('#history_table').bootstrapTable({
			//url: 'data1.json',
		   showExport: true,
		   pagination:true,                  
           pageNumber:1,                       //初始化加载第一页，默认第一页
           pageSize: 2,                       //每页的记录行数（*）
           pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*） 
		   columns: [
		    {
				field: 'id',
				title: '序号'
			},{
				field: 'carType',
				title: '车辆类型'
			},{
				field: 'numberPlate',
				title: '车牌号'
			}, {
				field: 'deviceId',
				title: '设备终端号'
			},{
				field: 'indi',
				title: '数据项'
			},{
				field: 'stateValue',
				title: '当前值'
			},{
				field: 'unit', 
				title: '单位'
			},{
				field: 'collectTime',
				title: '采集时间'
			}],
			data: [{
				id: '1',
				carType: '类型A',
				numberPlate: '苏A 56Y872',
				deviceId: '*******',
				indi: '温度1',
				stateValue: '3.0',
				unit: '˚C',
				collectTime: '2017-08-03 14:30:00'					
			},
			{
				id: '2',
				carType: '类型A',
				numberPlate: '苏A 56Y872',
				deviceId: '*******',
				indi: '温度1',
				stateValue: '5.0',
				unit: '˚C',
				collectTime: '2017-08-04 14:30:00'		
			},
			{
				id: '3',
				carType: '类型A',
				numberPlate: '苏A 56Y872',
				deviceId: '*******',
				indi: '温度1',
				stateValue: '4.0',
				unit: '˚C',
				collectTime: '2017-08-0514:30:00'	
			}		
			]
		}); 
   });	 
	  

var type =['监测数据','告警信息'];	
var indiValue =['温度1','温度2','温度3','湿度','总里程','充电电流','放电电流'];	
var alarmValue =['车体故障告警','温湿度告警','终端故障告警','电子围栏告警','通信状态告警'];	

function initSelectItem(){	 
	var strTp = "<select id='selectedType' style='width:50%' onchange='selectOnchang(this)'><option selected>--请选择--</option>"; 
	var strOption = "";
	    $(type).each(function(index,element){
			strOption+="<option>"+type[index]+"</option>";		
		});	
		$("#selType").html(strTp+strOption+"</select>");
	
	//设置默认展示项
	var strIndiValue = "<select id='selItem' style='width:50%' onchange='selectOnchang(this)'><option selected>--请选择--</option>"; 
	var strValue = "";					 
		$(indiValue).each(function(index,element){
			strValue+="<option>"+indiValue[index]+"</option>";		
		});		
	  	$("#selTypeItem").html(strIndiValue+strValue+"</select>");					
        $("#numberPlate").html("<input type='text' style='width:50%' id='numberPt' placeholder='请输入车牌号'>");		
	    $('#searchDateRange1').datetimepicker({
           clearBtn: true,
           autoclose: true,	   
		   formatDate:'yyyy-mm-dd hh:ii',
		   minuteStep :5  
		});
	    $('#searchDateRange2').datetimepicker({
	    clearBtn: true,
        autoclose: true,	
	    formatDate:'yyyy-mm-dd hh:ii',
	    minuteStep :5  
	    });		
}	
		
function selectOnchang(obj){
	var checkedValue = $("#selectedType").val();
		if(checkedValue==type[0]){
			$("#tdTitle").html("");	
			$("#tdTitle").html("<span>数据项*(必选):</span>");			
	    var strIndiValue = "<select id='selItem' style='width:40%' onchange='selectOnchang2(this)'><option selected>--请选择--</option>"; 
	    var strValue = "";					 
		$(indiValue).each(function(index,element){
			strValue+="<option>"+indiValue[index]+"</option>";		
		});		      	
		$("#selTypeItem").html(strIndiValue+strValue+"</select>");			
		}else if(checkedValue==type[1]){
			$("#tdTitle").html("");	
			$("#tdTitle").html("<span>告警类型*(必选):</span>");	
			 var strIndiValue = "<select id='alarmItem' style='width:40%' onchange='selectOnchang2(this)'><option selected>--请选择--</option>"; 
			 var strValue = "";					 
		     $(alarmValue).each(function(index,element){
				strValue+="<option>"+alarmValue[index]+"</option>";		
				});		
			 $("#selTypeItem").html(strIndiValue+strValue+"</select>");				
		}
}

function selectOnchang2(obj){
		
}


//查询条件
var queryParam=[];
//按条件查询历史记录
$("#history_search").on("click", function(){
	var selType = $("#selectedType").val();
	var selValue = $("#selTypeItem").find("option:selected").text();
	if(selType=='--请选择--'||selValue=='--请选择--')
		alert("请选择查询条件！");
	else{
	var selValue = $("#selTypeItem").find("option:selected").text();
   // var numberPlate = document.getElementById("numberPt").value; 
	var numberPlate = $("#numberPt").val();;
	var searchDateRange1 = $("#searchDateRange1").val();
    var searchDateRange2 = $("#searchDateRange2").val();
	queryParam.push(selType);
	queryParam.push(selValue);
	queryParam.push(numberPlate);
	queryParam.push(searchDateRange1);
	queryParam.push(searchDateRange2);
    alert(queryParam);
    //查询请求	
	}
});
//导出历史记录

